import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart';
import 'package:qh_music/src/widgets/audio/audio_playlist_mode_controller.dart';
import 'package:qh_music/src/widgets/audio/audio_progress.dart';
import 'package:qh_music/src/widgets/audio/volume_controller.dart';

class AudioControllerWidget extends StatelessWidget {
  final Player player;
  final double minWidth;

  const AudioControllerWidget(
      {super.key, required this.player, this.minWidth = 224});

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints(minWidth: minWidth),
      child: Column(
        children: [
          AudioProgressWidget(player: player),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              AudioPlaylistModeController(player: player),
              IconButton(
                onPressed: () {
                  player.previous();
                },
                icon: const Icon(Icons.skip_previous),
              ),
              IconButton(
                onPressed: () {
                  player.playOrPause();
                },
                icon: StreamBuilder(
                  stream: player.stream.playing,
                  builder: (context, playing) => Icon(
                    playing.data == true ? Icons.pause : Icons.play_arrow,
                  ),
                ),
              ),
              IconButton(
                onPressed: () {
                  player.next();
                },
                icon: const Icon(Icons.skip_next),
              ),
              VolumeControllerWidget(
                player: player,
              ),
            ],
          ),
        ],
      ),
    );
  }
}
